﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using XDeal.BL.Implements;
using Utility;
using XDeal.Common.Web;
using XDeal.Common.Constants;
using XDeal.DAL.Entities;
using Utility.Enums;

namespace XDEALWEB.Controllers
{
    public class HomeController : Controller
    {
        #region Variable
        int _itemPerpage = ConvertManage.ConvertToInt(WebCommons.GetValueFromAppSetting(ConstVariableName.CV_WCF_HomeItemPerPage), 5);
        int _pageSize = ConvertManage.ConvertToInt(WebCommons.GetValueFromAppSetting(ConstVariableName.CV_WCF_FrontEndPageSize), 5);
        #endregion

        //
        // GET: /Home/
        public ActionResult Index(int? page)
        {
            ViewDataListOfDeal(page);
            return View();
        }

        #region Private Functions
        /// <summary>
        /// View Data List Of Deals
        /// </summary>
        /// <param name="page"></param>
        private void ViewDataListOfDeal(int? page)
        {
            DealBL obDealBL = new DealBL();
            if (page == null || page <= 0)
                page = 1;            
            int totalItem = 0;
            
            //Get Data            
            List<Deal> lstDeal = obDealBL.GetAllDealByStatus((int)page, _itemPerpage, ref totalItem, DealStatus.Open);
            ViewData[ConstViewDataName.ListOfDeal] = lstDeal;
            
            //Get Link
            ViewData[ConstViewDataName.PagerLinkDeal] = Pager.GenerateLink(totalItem, _pageSize, _itemPerpage, (int)page, Request.RawUrl);
        }
        #endregion
    }
}
